﻿using System;
using System.Configuration;
using System.Data.Common;
using System.Web.UI.WebControls;

namespace JPR.TunelProxy.WebUi
{
    public partial class Statistic : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                Database db = new Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase(ConfigurationManager.ConnectionStrings["AccessLog"].ConnectionString);
                using (DbConnection connection = db.CreateConnection())
                using (DbCommand command = db.GetStoredProcCommand("dbo.Proxy_GetAccessLog"))
                {
                    command.Connection = connection;
                    connection.Open();
                    using (DbDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            TableRow row = new TableRow();
                            tblResult.Rows.Add(row);
                            TableCell cell = new TableCell();
                            row.Cells.Add(cell);
                            cell.Text = reader["RequestTime"].ToString();
                            cell = new TableCell();
                            row.Cells.Add(cell);
                            cell.Text = reader["Source"].ToString();
                            cell = new TableCell();
                            row.Cells.Add(cell);
                            cell.Text = reader["Destination"].ToString();
                            cell = new TableCell();
                            row.Cells.Add(cell);
                            cell.Text = reader["Result"].ToString();
                        }
                        reader.Close();
                    }
                    connection.Close();
                }
            }
            catch (Exception ex)
            {
                Literal literal = new Literal();
                literal.Text = ex.Message;
                form1.Controls.Add(literal);
            }
        }
    }
}
